define(function () {

    var self,
        item,
        updateData = {}
    ;

    var gwat600_01 = app.Module.extend({

        init: function () {
            self = this;
            self._super({
                _tag: 'gwat600_01' // key, 对象放进pageModule
            }, win);

            item = app.cloneJSON(app.pageParameters['gwat600_01_page']);
            self.imgArr = [];
            if (item.GWCV010 == null || item.GWCV010 == undefined) {
                item.GWCV010S = [];
            } else {
                item.GWCV010S = item.GWCV010.split(',');
            }
            mui.ready(function () {
                new Vue({
                    el: doc.getElementById('gwat600_01'),
                    data: function () {
                        return {
                            item: item,
                            imgs: self.imgArr
                        }
                    },
                    methods: {
                        btn_GWCS019: function () {
                            var vue = this;
                            app.scanQRCode(function (result) {
                                Vue.set(item, 'GWCS019', result);
                                app.ajax({
                                    xurl: "api/wx/gwat600/addGood",
                                    xdata: {
                                        GWCS019: result,
                                        GWCVENT: item.GWCSENT,
                                        GWAA003: app.cookie('_WX_ACCOUNT_')//微信号
                                    },
                                    cb: function (result) {
                                        if (result.ok) {
                                            if (result.data.data != null) {
                                                for (var i = 0; i < vue.item.list.length; i++) {
                                                    if (vue.item.list[i].GWCS019 == result.data.data.GWCS019) {
                                                        vue.item.list.splice(i, 1);
                                                        break;
                                                    }
                                                }
                                                vue.item.list.push(result.data.data);
                                            } else {
                                                app.toast('无设备信息');
                                            }
                                        } else {
                                            app.toast(result.data.message);
                                        }
                                    }
                                });
                            });
                        },
                        btn_GWCV006: function () {
                            app.scanQRCode(function (result) {
                                Vue.set(item, 'GWCV006', result);
                            });
                        },
                        delimg: function (i) {
                            self.imgArr.removei(i);
                        },
                        delimg2: function (i) {
                            item.GWCV010S.removei(i);
                        },
                        addImgs: function () {
                            app.chooseImageNew(function (imgs) {
                                //self.imgArr.pushArray(imgs);
                                for (var i = 0; i < imgs.length; i++) {
                                    self.imgArr.push({
                                        img: imgs[i].img,
                                        id: imgs[i].localId
                                    })
                                }
                            });
                        },
                        save: function () {
                            /*if(!self.validate()){
                             return;
                             }*/
                            app.showLoading();
                            app.uploadLocalIds({
                                ids: self.imgArr,
                                cb: function (imgs) {
                                    app.hideLoading();
                                    if (imgs.length > 0) {
                                        item.GWCV010 = item.GWCV010S.join(',');
                                        var imgurl = "";
                                        for (var i = 0; i < imgs.length; i++) {
                                            imgurl += (imgs[i].name + ",");
                                        }
                                        if (item.GWCV010) {
                                            item.GWCV010 += ',' + imgurl.substring(0,imgurl.length-1);//图片地址
                                        } else {
                                            item.GWCV010 = imgurl.substring(0,imgurl.length-1);//图片地址
                                        }
                                    }
                                    app.pageModule('p_gwat600').setValue(item);
                                    app.back(1);
                                }
                            });
                        },
                        ok: function () {
                            if (!self.validate()) {
                                return;
                            }
                            app.confirm({
                                msg: '是否回报？',
                                ok: function (e) {
                                    app.showLoading();
                                    app.uploadLocalIds({
                                        ids: self.imgArr,
                                        cb: function (imgs) {
                                            if (imgs.length > 0) {
                                                item.GWCV010 = item.GWCV010S.join(',');
                                                var imgurl = "";
                                                for (var i = 0; i < imgs.length; i++) {
                                                    imgurl += (imgs[i].name + ",");
                                                }
                                                if (item.GWCV010) {
                                                    item.GWCV010 += ',' + imgurl.substring(0,imgurl.length-1);//图片地址
                                                } else {
                                                    item.GWCV010 = imgurl.substring(0,imgurl.length-1);//图片地址
                                                }
                                            }
                                            app.ajax({
                                                xurl: "api/wx/gwat600/confirm",
                                                xdata: {
                                                    item: JSON.stringify(item)
                                                },
                                                cb: function (result) {
                                                    app.hideLoading();
                                                    if (result.ok) {
                                                        app.toast('回报成功');
                                                        app.pageModule('p_gwat600')._refresh();
                                                        app.back(1);
                                                    } else {
                                                        app.toast(result.data.message);
                                                    }
                                                }
                                            });
                                        }
                                    });
                                }
                            });
                        }
                    }
                });
            });
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });

        },
        validate: function () {
            if (item.GWCV006 == '' || item.GWCV006 == null) {
                app.toast('安装人员为空,请检查');
                return false;
            } else if (item.GWCV009 == '' || item.GWCV009 == null) {
                app.toast('安装日期为空,请检查');
                return false;
            }
            return true;
        }
    });
    return new gwat600_01();
});